﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace VPN
{
    public partial class UserList : MPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                System.Security.Principal.WindowsImpersonationContext wic =
                      ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
                GridView1.DataSource = VPN.Querier.UserHelper.GetAllUsers().Select(a =>
                    new
                    {
                        Name = a.Name,
                        LastLogon = a.LastLogon,
                        AccountExpirationDate = a.AccountExpirationDate,
                        Enabled = a.Enabled,
                        SID = a.Sid.ToString(),
                        Group = a.Description,
                        Expired = a.AccountExpirationDate.GetValueOrDefault(DateTime.MaxValue) < DateTime.Now,
                    }
                    ).OrderBy(a => a.Name);
                GridView1.DataBind();
                wic.Undo();
            }
        }

    }
}
